package com.smh.a02PaiXuDemo2;

import java.util.Random;

public class MaoPaoPaiXuDemo {
    public static void main(String[] args) {

        int[] arr = {12,34,51,21,23,12,32,43,12,3,234,2};
        int[] newarr = paixu(arr);
        for (int i = 0; i < newarr.length; i++) {
            System.out.print(newarr[i]+" ");
        }
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }

        int[] arr2 = new int[10000];
        Random random = new Random();
        for (int i = 0; i < arr2.length; i++) {
            arr2[i]=random.nextInt();
        }
        Long start = System.currentTimeMillis();
        paixu(arr2);
        Long end = System.currentTimeMillis();
        System.out.println(end-start);


    }
    public static int[] paixu(int[] arr){
        int flag=1;
        int temp=0;
        for (int i1 = 0; i1 < arr.length-1; i1++) {
            if (flag==0){
                return arr;
            }
            flag=0;
            for (int i = 1; i < arr.length-i1; i++) {
                if (arr[i-1]>arr[i]){
                    temp = arr[i-1];
                    arr[i-1]=arr[i];
                    arr[i]=temp;
                    flag=1;
                }
            }
        }
        return arr;
    }
}
